package com.guigu.servicegoods.config;

import com.guigu.servicegoods.service.TbBrandService;
import com.guigu.servicegoods.service.TbCategoryService;
import com.guigu.servicegoods.service.TbSkuService;
import com.guigu.servicegoods.service.TbStockBackService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class Init implements InitializingBean {

    @Autowired
    private TbCategoryService categoryService;

    @Autowired
    private TbSkuService skuService;

    @Autowired
    private TbStockBackService stockBackService;

    public void afterPropertiesSet() throws Exception {
        System.out.println("‐‐‐缓存预热‐‐‐");
        categoryService.saveCategoryTreeToRedis();//加载商品分类导航缓存
        skuService.saveAllPriceToRedis();//加载价格数据
    }

    @Scheduled(cron = "0 0 0/1 * * ?")
    public void orderTimeOutLogic(){
        System.out.println("执行库存回滚");
        stockBackService.doBack();
    }
}
